package shop;

import java.math.BigDecimal;
import java.util.Scanner;

/**
 * @Description：
 * @Author: 杨涌仁
 * @Date: 2022/10/13
 */
@SuppressWarnings({"all"})
public class BuyFruit {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        System.out.println("请输入购买顾客: ");
        System.out.println("输入exit则退出");
        String customer = sc.next();
        loop:
        while (true) {
            switch (customer) {
                case "A":
                    buyAppleAndStrawberry();
                    break loop;
                case "B":
                    buyAllFruit();
                    break loop;
                case "C":
                    buyAllAndStrawberryDiscount();
                    break loop;
                case "D":
                    buyAllFullReduce();
                    break loop;
                case "exit":
                    break;
                default:
                    System.out.println("输入错误,请重新输入顾客:");
                    customer = sc.next();
                    break;
            }
        }
    }

    /**
     * 以下是顾客A的购买方案
     */
    private static void buyAppleAndStrawberry() {

        int appleWeight = 0;
        int strawberryWeight = 0;
        try {
            System.out.println("请输入顾客购买苹果的重量(斤)：");
            appleWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买草莓的重量(斤)");
            strawberryWeight = Integer.parseInt(sc.next());
            double appleTotalPay = new ApplePay().totalPay(appleWeight);
            double strawberryTotalPay = new StrawberryPay().totalPay(strawberryWeight);
            double totalPay = new BigDecimal(appleTotalPay).add(new BigDecimal(strawberryTotalPay)).doubleValue();
            System.out.println("购买商品所需支付的金额：" + totalPay);
        } catch (NumberFormatException e) {
            System.out.println("输入的水果的重量不是整数");
        }

    }

    /**
     * 以下是顾客B的购买方案
     */
    private static void buyAllFruit() {
        int appleWeight = 0;
        int strawberryWeight = 0;
        int mangoWeight = 0;
        try {
            System.out.println("请输入顾客购买苹果的重量(斤)：");
            appleWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买草莓的重量(斤)");
            strawberryWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买芒果的重量(斤)");
            mangoWeight = Integer.parseInt(sc.next());

            double appleTotalPay = new ApplePay().totalPay(appleWeight);
            double strawberryTotalPay = new StrawberryPay().totalPay(strawberryWeight);
            double mangoTotalPay = new MangoPay().totalPay(mangoWeight);
            double totalPay = new BigDecimal(appleTotalPay)
                    .add(new BigDecimal(strawberryTotalPay))
                    .add(new BigDecimal(mangoTotalPay))
                    .doubleValue();
            System.out.println("购买商品所需支付的金额：" + totalPay);

        } catch (NumberFormatException e) {
            System.out.println("输入的水果的重量不是整数");
        }


    }

    /**
     * 以下是顾客C的购买方案
     */
    private static void buyAllAndStrawberryDiscount() {
        int appleWeight = 0;
        int strawberryWeight = 0;
        int mangoWeight = 0;
        try {
            System.out.println("请输入顾客购买苹果的重量(斤)：");
            appleWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买草莓的重量(斤)");
            strawberryWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买芒果的重量(斤)");
            mangoWeight = Integer.parseInt(sc.next());

            double appleTotalPay = new ApplePay().totalPay(appleWeight);
            double strawberryTotalPay = new StrawberryPay().strawberryDiscountPay(strawberryWeight);
            double mangoTotalPay = new MangoPay().totalPay(mangoWeight);
            double totalPay = new BigDecimal(appleTotalPay)
                    .add(new BigDecimal(strawberryTotalPay))
                    .add(new BigDecimal(mangoTotalPay))
                    .doubleValue();

            System.out.println("购买商品所需支付的金额：" + totalPay);

        } catch (NumberFormatException e) {
            System.out.println("输入的水果的重量不是整数");
        }

    }

    /**
     * 以下是顾客D的购买方案
     */
    private static void buyAllFullReduce() {
        int appleWeight = 0;
        int strawberryWeight = 0;
        int mangoWeight = 0;
        try {
            System.out.println("请输入顾客购买苹果的重量(斤)：");
            appleWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买草莓的重量(斤)");
            strawberryWeight = Integer.parseInt(sc.next());
            System.out.println("请输入顾客购买芒果的重量(斤)");
            mangoWeight = Integer.parseInt(sc.next());

            double appleTotalPay = new ApplePay().totalPay(appleWeight);
            double strawberryTotalPay = new StrawberryPay().strawberryDiscountPay(strawberryWeight);
            double mangoTotalPay = new MangoPay().totalPay(mangoWeight);
            double buyAllFullPay = new BigDecimal(appleTotalPay)
                    .add(new BigDecimal(strawberryTotalPay))
                    .add(new BigDecimal(mangoTotalPay))
                    .doubleValue();

            // 加大促销力度以后，满100减10
            if (buyAllFullPay > 100) {
                double totalPay = new BigDecimal(String.valueOf(buyAllFullPay))
                        .subtract(BigDecimal.valueOf((buyAllFullPay / 100) * 10)).doubleValue();
                System.out.println("购买商品支付的金额：" + totalPay);
            } else {
                System.out.println("购买商品支付的金额：" + buyAllFullPay);
            }

        } catch (NumberFormatException e) {
            System.out.println("输入的水果的重量不是整数");
        }

    }
}
